//
//  RouteDetailView.m
//  TravelFirst
//
//  Created by lanou3g on 15/9/22.
//  Copyright (c) 2015年 吴娅君. All rights reserved.
//

#import "RouteDetailView.h"

@implementation RouteDetailView

- (instancetype)initWithFrame:(CGRect)frame imageArray:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector Height:(CGFloat)h num:(NSInteger)num commentone:(CGFloat)comone commenttwo:(CGFloat)comtwo acttotal:(NSInteger)acttotal albumImgArr:(NSMutableArray *)albumImgArr albumaction:(SEL)albumaction albumtimer:(NSTimeInterval)albumtimer albumselector:(SEL)albumselector lastArr:(NSMutableArray *)lastArr{
    self = [super initWithFrame:frame];
    if(self){
        _secoll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, kHeight)];
        //设置ScrollerView的相关属性
        
        [self addSubview:_secoll];
        [self setscrollImg:imageArray delegate:delegate action:action timer:timer selector:selector];
        [self setValView:h];
        [self setpeople:num];
        [self setcomment:comone two:comtwo];
        if(acttotal!=0){
            [self setavt:acttotal];
            if(acttotal==1){
                [self setalbum:_v.frame.origin.y+_v.frame.size.height+10 imgArr:albumImgArr delegate:delegate action:albumaction timer:albumtimer selector:albumselector];
            }else{
                [self setalbum:_vv.frame.origin.y+_vv.frame.size.height+10 imgArr:albumImgArr delegate:delegate action:albumaction timer:albumtimer selector:albumselector];
            }
        }else{
            [self setalbum:_contenttwo.frame.origin.y+_contenttwo.frame.size.height+10 imgArr:albumImgArr delegate:delegate action:albumaction timer:albumtimer selector:albumselector];
        }
        [self setRelatedroute:lastArr];
        
    }
    return self;
}
//轮播图和上面的图片
-(void)setscrollImg:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector{
    NSMutableArray *insterArray = [NSMutableArray arrayWithArray:imageArray];
    //把imageArray的最后一个插入到第0个
    [insterArray insertObject:[imageArray objectAtIndex:imageArray.count - 1] atIndex:0];
    [insterArray insertObject:[imageArray objectAtIndex:0] atIndex:imageArray.count + 1];
    _scr=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, kWidth, 250)];
    //设置ScrollerView的相关属性
    _scr.contentSize = CGSizeMake(kWidth * insterArray.count, 0);
    _scr.pagingEnabled = YES;
    _scr.showsHorizontalScrollIndicator = YES;
    _scr.bounces = NO;
    _scr.delegate = delegate;
    _scr.contentOffset = CGPointMake(kWidth, 0);
    [_secoll addSubview:_scr];
    //循环创建imageView
    for(int i = 0; i < insterArray.count ;i++){
        TapImageView *imageTap = [[TapImageView alloc] initWithFrame:CGRectMake(i  * kWidth, 0, kWidth, _scr.bounds.size.height) taget:delegate action:action];
        RouteDetailModel *model = insterArray[i];
        [imageTap sd_setImageWithURL:[NSURL URLWithString:model.picture]];
        [_scr addSubview:imageTap];
    }
    //创建定时器
    [NSTimer scheduledTimerWithTimeInterval:timer target:delegate selector:selector userInfo:nil repeats:YES];
    _lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 200, kWidth, 50)];
    _lab.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:_lab];
}

//内容
-(void)setValView:(CGFloat)h{
    _titlelab=[[UILabel alloc]initWithFrame:CGRectMake(10, _scr.frame.size.height+10, 100, 50)];
    [_secoll addSubview:_titlelab];
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(10, _titlelab.frame.origin.y+40, 15, 15)];
    img.image=[UIImage imageNamed:@"icon_location_gray_12x12@2x"];
    [_secoll addSubview:img];
    _citylab=[[UILabel alloc]initWithFrame:CGRectMake(30, _titlelab.frame.origin.y+40, 100, 15)];
        _citylab.font=[UIFont boldSystemFontOfSize:11];
    _citylab.textColor=[UIColor grayColor];
    [_secoll addSubview:_citylab];
    _contentlab=[[UILabel alloc]initWithFrame:CGRectMake(10, _citylab.frame.origin.y+20, kWidth-20, h)];
    _contentlab.numberOfLines=0;
    _contentlab.lineBreakMode=NSLineBreakByWordWrapping;
    _contentlab.font=[UIFont fontWithName:@"Arial" size:12];
    [_secoll addSubview:_contentlab];
    UIView *line=[[UIView alloc]initWithFrame:CGRectMake(0, _contentlab.frame.origin.y+_contentlab.frame.size.height+20, kWidth, 0.5)];
    line.backgroundColor=[UIColor grayColor];
    [_secoll addSubview:line];
}

-(void)setpeople:(NSInteger)num{
    UILabel *tit=[[UILabel alloc]initWithFrame:CGRectMake(10, _contentlab.frame.origin.y+_contentlab.frame.size.height+50, kWidth, 30)];
    tit.text=@"适合人群";
    tit.textColor=[UIColor grayColor];
    tit.font=[UIFont boldSystemFontOfSize:15];
    [_secoll addSubview:tit];
    _people=[[UILabel alloc]initWithFrame:CGRectMake(10, tit.frame.origin.y+tit.frame.size.height+10, kWidth, ceil(num/3.0)*30)];
    [_secoll addSubview:_people];
    
}
//设置内容
-(void)setVal:(RouteDetailModel *)model{
    _titlelab.text=model.name;
    _citylab.text=model.destination;
    _contentlab.text=model.detail;
}
//设置适合人群
-(void)people:(NSMutableArray *)arr{
    int sum=0;
    for(int i=0;i<ceil(arr.count/3.0);i++){
        int temp;
        if((i+1)==ceil(arr.count/3.0)&&arr.count%3!=0){
            temp=arr.count%3;
        }else{
            temp=3;
        }
        for(int j=0;j<temp;j++){
            UILabel *l=[[UILabel alloc]initWithFrame:CGRectMake(j*80, i*30, 70, 20)];
            l.backgroundColor=[UIColor colorWithRed: 90% 256 / 255.0 green:200% 256 / 255.0 blue:255% 256 / 255.0 alpha:1];
            l.text=[NSString stringWithFormat:@"%@ +%@",arr[sum][@"name"],arr[sum][@"count"]];
            l.font=[UIFont boldSystemFontOfSize:12];
            l.textColor=[UIColor whiteColor];
            l.textAlignment=1;
            sum++;
            [_people addSubview:l];
        }
    }
}

-(void)setIMG:(NSMutableArray *)Imgarr{
    if(Imgarr.count==0){
         _lab.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:0];
        return;
    }
    for(int i=0;i<Imgarr.count;i++){
        UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake((i*50)+10, _lab.frame.origin.y+5, 40, 40)];
        [img sd_setImageWithURL:[NSURL URLWithString:Imgarr[i]]];
        [_secoll addSubview:img];
    }
}

//评价
-(void)setcomment:(CGFloat)onecom two:(CGFloat)twocom{
    _comment=[[UIView alloc]initWithFrame:CGRectMake(0, _people.frame.origin.y+_people.frame.size.height+20, kWidth, 50)];
    _comment.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:_comment];
    UILabel *tit=[[UILabel alloc]initWithFrame:CGRectMake(10, 20, 40, 10)];
    tit.textColor=[UIColor grayColor];
    tit.text=@"评价";
    tit.font=[UIFont boldSystemFontOfSize:14];
    [_comment addSubview:tit];
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(kWidth-30, 15, 20, 20)];
    img.image=[UIImage imageNamed:@"btn_go_me_13x13@3x"];
    [_comment addSubview:img];
    _total=[[UILabel alloc]initWithFrame:CGRectMake(kWidth-100, 15, 70, 20)];
    _total.text=@"全部54评价";
    _total.textColor=[UIColor grayColor];
    _total.font=[UIFont boldSystemFontOfSize:12];
    [_comment addSubview:_total];
    //第一个评论
    _contentone=[[UIView alloc]initWithFrame:CGRectMake(0, _comment.frame.origin.y+_comment.frame.size.height+2, kWidth, onecom+85)];
    _contentone.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:_contentone];
    _userone=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    
    //允许设置
    _userone.layer.masksToBounds=YES;
    _userone.layer.borderWidth=2;
    _userone.layer.cornerRadius=_userone.bounds.size.height/2;
    _userone.layer.borderColor=[UIColor whiteColor].CGColor;
    [_contentone addSubview:_userone];
    //设置评论
    _nameone=[[UILabel alloc]initWithFrame:CGRectMake(70, 10, 100, 20)];
    
    _nameone.font=[UIFont boldSystemFontOfSize:13];
    [_contentone addSubview:_nameone];
    _dateone=[[UILabel alloc]initWithFrame:CGRectMake(kWidth-100, 40, 100, 20)];
    
    _dateone.font=[UIFont boldSystemFontOfSize:10];
    _dateone.textColor=[UIColor grayColor];
    [_contentone addSubview:_dateone];
    _conone=[[UILabel alloc]initWithFrame:CGRectMake(10, _userone.frame.size.height+20, kWidth-30 , onecom)];
    _conone.numberOfLines=0;
    _conone.font=[UIFont systemFontOfSize:12];
    [_contentone addSubview:_conone];
    //第二个评论
    _contenttwo=[[UIView alloc]initWithFrame:CGRectMake(0, _contentone.frame.origin.y+_contentone.frame.size.height+1, kWidth, twocom+85)];
    _contenttwo.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:_contenttwo];
    _usertwo=[[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    
    //允许设置
    _usertwo.layer.masksToBounds=YES;
    _usertwo.layer.borderWidth=2;
    _usertwo.layer.cornerRadius=_usertwo.bounds.size.height/2;
    _usertwo.layer.borderColor=[UIColor whiteColor].CGColor;
    [_contenttwo addSubview:_usertwo];
    //设置评论
    _nametwo=[[UILabel alloc]initWithFrame:CGRectMake(70, 10, 100, 20)];
    
    _nametwo.font=[UIFont boldSystemFontOfSize:13];
    [_contenttwo addSubview:_nametwo];
    _datetwo=[[UILabel alloc]initWithFrame:CGRectMake(kWidth-100, 40, 100, 20)];
    
    _datetwo.font=[UIFont boldSystemFontOfSize:10];
    _datetwo.textColor=[UIColor grayColor];
    [_contenttwo addSubview:_datetwo];
    _contwo=[[UILabel alloc]initWithFrame:CGRectMake(10, _usertwo.frame.size.height+20, kWidth-30 , twocom)];
    _contwo.numberOfLines=0;
    _contwo.font=[UIFont systemFontOfSize:12];
    [_contenttwo addSubview:_contwo];
}

//设置评论值
-(void)setCommentVal:(NSUInteger)total modelone:(RouteCommentModel *)modelone modeltwo:(RouteCommentModel *)modeltwo{
    for (int i=1; i<total+1; i++) {
        if(i%2==0){
            UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*10+20, 16, 15, 15)];
            imgs.image=[UIImage imageNamed:@"img_star_11x11@3x"];
            [_comment addSubview:imgs];
        }
        if(i==total && total%2==1){
            UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*10+30, 16, 15, 15)];
            imgs.image=[UIImage imageNamed:@"img_star_half_11x11@3x"];
            [_comment addSubview:imgs];
        }
        if(i==total){
            UILabel *f=[[UILabel alloc]initWithFrame:CGRectMake(i*10+50, 16, 40, 15)];
            f.textColor=[UIColor orangeColor];
            f.font=[UIFont boldSystemFontOfSize:11];
            f.text=[NSString stringWithFormat:@"%ld.0",(unsigned long)total];
            [_comment addSubview:f];
        }
    }
    for(int i=0;i<modelone.score;i++){
        UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*20+70, 35, 15, 15)];
        imgs.image=[UIImage imageNamed:@"img_star_11x11@3x"];
        [_contentone addSubview:imgs];
    }
    [_userone sd_setImageWithURL:[NSURL URLWithString:modelone.created_by[@"avatar"]]];
    _nameone.text=modelone.created_by[@"nickname"];
    _dateone.text=[self Date:modelone.created_date style:@"YYYY/MM/dd HH:mm"];
    _conone.text=modelone.comment;
    for(int i=0;i<modeltwo.score;i++){
        UIImageView *imgs=[[UIImageView alloc]initWithFrame:CGRectMake(i*20+70, 35, 15, 15)];
        imgs.image=[UIImage imageNamed:@"img_star_11x11@3x"];
        [_contenttwo addSubview:imgs];
    }
    [_usertwo sd_setImageWithURL:[NSURL URLWithString:modeltwo.created_by[@"avatar"]]];
    _nametwo.text=modeltwo.created_by[@"nickname"];
    _datetwo.text=[self Date:modelone.created_date style:@"YYYY/MM/dd HH:mm"];
    _contwo.text=modeltwo.comment;
}

-(void)setavt:(NSInteger)acttotal{
    UIView *view=[[UIView alloc]initWithFrame:CGRectMake(0, _contenttwo.frame.origin.y+_contenttwo.frame.size.height+20, kWidth, 50)];
    view.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:view];
    UILabel *tit=[[UILabel alloc]initWithFrame:CGRectMake(10, 20, 100, 10)];
    tit.textColor=[UIColor grayColor];
    tit.text=@"近期活动";
    tit.font=[UIFont boldSystemFontOfSize:14];
    [view addSubview:tit];
    UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(kWidth-30, 15, 20, 20)];
    img.image=[UIImage imageNamed:@"btn_go_me_13x13@3x"];
    [view addSubview:img];
    _acttotal=[[UILabel alloc]initWithFrame:CGRectMake(kWidth-90, 15, 70, 20)];
    _acttotal.text=[NSString stringWithFormat:@"全部%ld活动",acttotal];
    _acttotal.textColor=[UIColor grayColor];
    _acttotal.font=[UIFont boldSystemFontOfSize:12];
    [view addSubview:_acttotal];
    
    _v=[[UIView alloc]initWithFrame:CGRectMake(0, view.frame.origin.y+view.frame.size.height+2 , kWidth, 65)];
    _v.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
    [_secoll addSubview:_v];
    _monthOne=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
    
    _monthOne.font=[UIFont systemFontOfSize:40];
    _monthOne.textColor=[UIColor colorWithRed:39% 256 / 255.0 green:189% 256 / 255.0 blue:255% 256 / 255.0 alpha:1];
    [_v addSubview:_monthOne];
    _andone=[[UILabel alloc]initWithFrame:CGRectMake(60, 15, 200, 20)];
    
    _andone.font=[UIFont systemFontOfSize:14];
    [_v addSubview:_andone];
    _clubone=[[UILabel alloc]initWithFrame:CGRectMake(60, 30, kWidth-100, 30)];

    _clubone.font=[UIFont boldSystemFontOfSize:14];
    _clubone.textColor=[UIColor grayColor];
    [_v addSubview:_clubone];
    if(acttotal>=2){
        _vv=[[UIView alloc]initWithFrame:CGRectMake(0, view.frame.origin.y+view.frame.size.height+68, kWidth, 65)];
        _vv.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:1];
        [_secoll addSubview:_vv];
        _monthtwo=[[UILabel alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
        
        _monthtwo.font=[UIFont systemFontOfSize:40];
        _monthtwo.textColor=[UIColor colorWithRed:39% 256 / 255.0 green:189% 256 / 255.0 blue:255% 256 / 255.0 alpha:1];
        [_vv addSubview:_monthtwo];
        _andtwo=[[UILabel alloc]initWithFrame:CGRectMake(60, 15, 200, 20)];
        
        _andtwo.font=[UIFont systemFontOfSize:14];
        [_vv addSubview:_andtwo];
        _clubtwo=[[UILabel alloc]initWithFrame:CGRectMake(60, 30, kWidth-100, 30)];
        
        _clubtwo.font=[UIFont boldSystemFontOfSize:14];
        _clubtwo.textColor=[UIColor grayColor];
        [_vv addSubview:_clubtwo];
    }
    
    
}

-(void)setAct:(NSMutableArray *)arr{
    RouteCommentModel *model1 = arr[0];
    NSString *str1=[self Date:model1.start_time style:@"MM月dd日"];
    _monthOne.text=[str1 substringToIndex:2];
    _andone.text=[NSString stringWithFormat:@"%@ | %@出发",[str1 substringFromIndex:2],model1.city];
    _clubone.text=model1.club[@"title"];
    if(arr.count>1){
        
        RouteCommentModel *model2 = arr[1];
        NSString *str2=[self Date:model2.start_time style:@"MM月dd日"];
        _monthtwo.text=[str2 substringToIndex:2];
        _andtwo.text=[NSString stringWithFormat:@"%@ | %@出发",[str2 substringFromIndex:2],model2.city];
        _clubtwo.text=model2.club[@"title"];
    }
}
//精选专辑
-(void)setalbum:(CGFloat)height imgArr:(NSMutableArray *)imageArray delegate:(id)delegate action:(SEL)action timer:(NSTimeInterval)timer selector:(SEL)selector{
    UILabel *tit=[[UILabel alloc]initWithFrame:CGRectMake(10, height, kWidth-20, 30)];
    tit.textColor=[UIColor grayColor];
    tit.text=@"精选专辑";
    tit.font=[UIFont boldSystemFontOfSize:14];
    [_secoll addSubview:tit];
    
    NSMutableArray *insterArray = [NSMutableArray arrayWithArray:imageArray];
    //把imageArray的最后一个插入到第0个
    
    
    [insterArray insertObject:[imageArray objectAtIndex:imageArray.count - 1] atIndex:0];
    [insterArray insertObject:[imageArray objectAtIndex:0] atIndex:imageArray.count + 1];
    
    _albumscr=[[UIScrollView alloc]initWithFrame:CGRectMake(10, tit.frame.origin.y+tit.frame.size.height+10, kWidth-20, 200)];
    //设置ScrollerView的相关属性
    _albumscr.contentSize = CGSizeMake((kWidth-20) * insterArray.count, 0);
    _albumscr.pagingEnabled = YES;
    _albumscr.showsHorizontalScrollIndicator = YES;
    _albumscr.bounces = NO;
    _albumscr.delegate = delegate;
    _albumscr.contentOffset = CGPointMake(kWidth-20, 0);
    [_secoll addSubview:_albumscr];
    NSLog(@"%lu",(unsigned long)insterArray.count);
    //循环创建imageView
    for(int i = 0; i < insterArray.count ;i++){
        TapImageView *imageTap = [[TapImageView alloc] initWithFrame:CGRectMake(i  * _albumscr.frame.size.width, 0, _albumscr.frame.size.width, _albumscr.bounds.size.height) taget:delegate action:action];
        RoutealbumModel *model = insterArray[i];
        [imageTap sd_setImageWithURL:[NSURL URLWithString:model.cover]];
        [_albumscr addSubview:imageTap];
        UILabel *lab=[[UILabel alloc]initWithFrame:CGRectMake(0, 180, kWidth-20, 20)];
        lab.backgroundColor=[UIColor colorWithRed: 231% 256 / 255.0 green:231% 256 / 255.0 blue:231% 256 / 255.0 alpha:0.9];
        lab.text=[NSString stringWithFormat:@"  %@ %@图 · by %@",model.start_date,model.photo_number,model.created_by[@"nickname"]];
        lab.font=[UIFont boldSystemFontOfSize:10];
        lab.textAlignment=0;
        lab.textColor=[UIColor grayColor];
        [imageTap addSubview:lab];
        UIImageView *userone=[[UIImageView alloc]initWithFrame:CGRectMake(kWidth-60, 165, 30, 30)];
        [userone sd_setImageWithURL:[NSURL URLWithString:model.created_by[@"avatar"]]];
        //允许设置
        userone.layer.masksToBounds=YES;
        userone.layer.borderWidth=1;
        userone.layer.cornerRadius=userone.bounds.size.height/2;
        userone.layer.borderColor=[UIColor whiteColor].CGColor;
        [imageTap addSubview:userone];
    }
    //创建定时器
    if(insterArray.count!=1){
        [NSTimer scheduledTimerWithTimeInterval:timer target:delegate selector:selector userInfo:nil repeats:YES];
    }
    
    
}

//设置相关路线
-(void)setRelatedroute:(NSMutableArray *)lastArr{
    UILabel *tit=[[UILabel alloc]initWithFrame:CGRectMake(10, _albumscr.frame.size.height+_albumscr.frame.origin.y+10, kWidth-20, 30)];
    tit.textColor=[UIColor grayColor];
    tit.text=@"相关路线";
    tit.font=[UIFont boldSystemFontOfSize:14];
    [_secoll addSubview:tit];
    for(int i=0;i<3;i++){
        UIImageView *img=[[UIImageView alloc]initWithFrame:CGRectMake(((kWidth-20)/3*i)+10, tit.frame.origin.y+tit.frame.size.height+10, (kWidth-20)/3-10, (kWidth-20)/3-10)];
        img.backgroundColor=[UIColor whiteColor];
        [img sd_setImageWithURL:[NSURL URLWithString:lastArr[i][@"cover"]]];
        [_secoll addSubview:img];
        UILabel *name=[[UILabel alloc]initWithFrame:CGRectMake(0, img.frame.size.height-20, img.frame.size.width, 20)];
        name.font=[UIFont systemFontOfSize:14];
        name.backgroundColor=[UIColor colorWithRed: 30% 256 / 255.0 green:31% 256 / 255.0 blue:40% 256 / 255.0 alpha:0.5];
        name.text=lastArr[i][@"name"];
        name.textColor=[UIColor whiteColor];
        name.textAlignment=1;
        [img addSubview:name];
    }
    _secoll.contentSize = CGSizeMake(kWidth , tit.frame.origin.y+tit.frame.size.height+260);
    UIView *clock = [[UIView alloc] initWithFrame:CGRectMake(0, kHeight - 120, kWidth, 60)];
    clock.backgroundColor = [UIColor blackColor];
    
    NSArray *arr1 = @[@"想去",@"去过"];
    NSArray *arr2 = @[@"icon_wanttogo_25x25@3x",@"icon_foot_25x25@3x"];
    for (int i = 0; i < 2; i++) {
        UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(i *(kWidth/2), 0, kWidth/2, 60)];
        button.tag = 600+i;
        [clock addSubview:button];
        
        UIImageView *pi = [[UIImageView alloc] initWithFrame:CGRectMake(50, 15, button.frame.size.width/5, 35)];
        pi.image = [UIImage imageNamed:arr2[i]];
        UILabel *text = [[UILabel alloc] initWithFrame:CGRectMake(button.frame.size.width/2, 0, button.frame.size.width/2, 60)];
        text.textColor = [UIColor whiteColor];
        text.text = arr1[i];
        text.font=[UIFont systemFontOfSize:15];
        
        [button addSubview:pi];
        [button addSubview:text];
    }
    [self addSubview:clock];
}

//将时间戳转化为时间
- (NSString *)Date:(NSString *)str style:(NSString *)style{
    NSTimeInterval time=[str doubleValue];
    NSDate *detaildate=[NSDate dateWithTimeIntervalSince1970:time];
    //实例化一个NSDateFormatter对象
    NSDateFormatter *dateFormatter = [[NSDateFormatter alloc] init];
    //设定时间格式,这里可以设置成自己需要的格式
    [dateFormatter setDateFormat:style];
    NSString *currentDateStr = [dateFormatter stringFromDate: detaildate];
    return currentDateStr;
}


@end
